handle 0 and NULL value of NTH_VALUE function #12676
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #12320.
Rationale for this change
The root cause in #12320 is because
get_signed_integer_value
will return an error onNULL
orInt64(NULL)
value. To process thenth_value
function, it requires then
value should be an integer. Therefore, I decided to convertNULL
value to 0 inget_signed_integer_value
and implement handler for the0
case. This will evaluate to NULL value for thenth_value(v1, NULL)
expression.Furthermore, it also evaluate the
nth_value(v1, 0)
to NULL instead of generating panic, which match the expected behaviour in duckdb.What changes are included in this PR?
[x] Return 0 for NULL value in
get_signed_integer
[x] Handle nth_value execution when n is 0
[x] Test file updated to test
nth_value(v2, 0)
,nth_value(v2, NULL)
andnth_value(v2, v2 * NULL)
.Are these changes tested?
Yes
Are there any user-facing changes?